//获取应用实例
var app = getApp();
Page({
    data: {
        //处理订单
        orderStatusDoingText:"处理订单",
        orderStatusFinishText:"订单完成",
        orderStatusClass: "icon_end",
        orderStatusAdd: "icon_doing",
        orderStatusToAdd: "icon_end",
        orderStatusTextClass: "",
        orderStatusExplainClass: "icon_order_succeed",
        orderStatusLineColour: "",
        "isShowFootNav": false,
		statusName: "",
		statusDescDetail: "",
		orderTitle: "",
		totalServiceAmount: "",
		orderAmount: "",
		eOrderAddress: "",
		processTitle: "",
		orderId: "",
		isShowPage: true,  //显示页面
		isShowCountBtn: false //倒计时按钮显示
	},
	
	countDown(second) {
		console.log(second)
		if (second > 0) {
			let that = this;
			let repeat= setInterval(()=>{
				second--;
				that.setData({
					countDown: second
				});
				if (second == 0) {
					clearInterval(repeat);
					that.setData({
						countDown: second,
						isShowCountBtn: false
					});
				} 
			}, 1000); //每1000毫秒即1秒执行一次此函数
		}else{
			console.log(second,'float')
			this.setData({
				countDown: second,
				isShowCountBtn: false
			});
		}
	},

	//取消订单
	cancelOrder(){
		let that = this,
			orderId = this.data.orderId;
		let opt = {
			url: app.globalData.host+"/wx/sd/co.ajax",				
			data: {
				'orderId': orderId,
				'payType': 0
			},
			sucFn: (result) => {
				app.errorToast('已成功取消订单');
				setTimeout(()=>{
					that.requestData(orderId)
					that.setData({
						isShowCountBtn: false
					})
				},1000)
				
				
			}
		}
		app.ajax(opt);
	},

	requestData(orderId){
		let that = this;
		
        let opt = {
            url: app.globalData.host+"/wx/sd/detail.ajax",
            data: {
                'orderId': orderId 
            },
            sucFn:(result)=> {
				let res = result.body;
				that.countDown(res.timeDiffer)
                that.setData({
					expressNbr: res.expressNbr,
					isShowCountBtn: res.status == 2&&res.timeDiffer != 0?true:false, //接口请求完显示倒计时按钮
					countDown: res.timeDiffer,
	                orderStatusExplainTextClass_f: res.status==3|| res.status==4|| res.status==5?'font-color-red':'',
	                orderStatusExplainClass: res.status==3|| res.status==4|| res.status==5?'icon_oeder_close_off':'icon_order_succeed',
					isShowPage: true,
					statusName: res.statusName,
					statusDescDetail: res.statusDescDetail,
	                processTitle: res.processlist[0].name,
					processTime: app.toYMDHMSDate(res.processlist[0].createTime),
	                orderId: orderId,
	                createTime: app.toYMDHMSDate(res.createTime),
	                payTime: app.toYMDHMSDate(res.payTime),
					address: res.address.fullAddr,
					contactName: res.address.contactName,
					cellNum: res.address.cellNum,
	                mailingAddressRange: res.mailingAddressRange == 1?'普通快递':res.mailingAddressRange == 2?'香港快递':'无',
					goodType: res.goodType == '01'?'文件':
							  res.goodType == '02'?'数码产品':
							  res.goodType == '03'?'生活用品':
							  res.goodType == '04'?'校园包裹':
							  res.goodType == '05'?'其他物品':
							  '',
					payType: res.payType==0?'到付':res.payType==2?'支付宝':res.payType==3?'微信':'',
	                completeText: res.status==4?'关闭时间':res.status==8?'完成时间':'',
	                completeTime: app.toYMDHMSDate(res.completeTime),
	                completeTimeIsShow: res.completeTime?true:false

                });
                switch (result.body.status) {   //result.body.status
	                /*
	                 * style.icon_success      成功绿色大圆
	                 * style.icon_error        失败红色大圆
	                 * style.icon_moren_error  失败红色中圆
	                 * style.icon_moren        默认灰色中圆
	                 *
	                 * bg-color_blue 蓝色背景
	                 * bg-color_red  红色背景
	                 * */
	                case 0:
		                that.setData({
			                orderStatusTwoText:"处理订单",
			                orderStatusThreeText:"订单完成",

			                orderStatusOne: "icon_doing",
			                orderStatusTwo: "",
			                orderStatusThree: "",
			                orderSideOneLineColour: "",
			                orderSideTwoLineColour: "",
			                orderSideThreeLineColour: "",

			                orderStatusTwoTextColour: "",
			                orderStatusThreeTextColour: ""

		                });
		                break;

					case 1:
						that.setData({
			                orderStatusTwoText:"处理订单",
			                orderStatusThreeText:"订单完成",

			                orderStatusOne: "bg-color-blue",
			                orderStatusTwo: "icon_doing",
			                orderStatusThree: "",

			                orderSideOneLineColour: "bg-color-blue",
			                orderSideTwoLineColour: "bg-color-blue",
			                orderSideThreeLineColour: "",

			                orderStatusTwoTextColour: "font-color-blue",
			                orderStatusThreeTextColour: ""

		                });
		                break;

	                case 2:
						that.setData({
			                orderStatusTwoText:"处理订单",
			                orderStatusThreeText:"订单完成",

			                orderStatusOne: "bg-color-blue",
			                orderStatusTwo: "icon_doing",
			                orderStatusThree: "",

			                orderSideOneLineColour: "bg-color-blue",
			                orderSideTwoLineColour: "bg-color-blue",
			                orderSideThreeLineColour: "",

			                orderStatusTwoTextColour: "font-color-blue",
			                orderStatusThreeTextColour: ""

		                });
		                break;
	                case 3:
						that.setData({
			                orderStatusTwoText:"办理失败",
			                orderStatusThreeText:"订单完成",

			                orderStatusOne: "bg-color-blue",
			                orderStatusTwo: "icon_fail",
			                orderStatusThree: "",

			                orderSideOneLineColour: "bg-color-red",
			                orderSideTwoLineColour: "bg-color-red",
			                orderSideThreeLineColour: "",

			                orderStatusTwoTextColour: "font-color-red",
			                orderStatusThreeTextColour: ""

		                });
		                break;
	                case 4:
						that.setData({
			                orderStatusTwoText:"办理失败",
			                orderStatusThreeText:"订单关闭",

			                orderStatusOne: "bg-color-blue",  //成功大圆
			                orderStatusTwo: "icon_failed", //失败中圆
			                orderStatusThree: "icon_fail",  //失败的大圆

			                orderSideOneLineColour: "bg-color-blue",
			                orderSideTwoLineColour: "bg-color-blue",
			                orderSideThreeLineColour: "bg-color-red",

			                orderStatusTwoTextColour: "font-color-red",
			                orderStatusThreeTextColour: "font-color-red"

		                });
		                break;

	                case 5:
						that.setData({
			                orderStatusTwoText:"办理失败",
			                orderStatusThreeText:"订单已失效",

			                orderStatusOne: "bg-color-blue",  //成功大圆
			                orderStatusTwo: "icon_failed", //失败中圆
			                orderStatusThree: "icon_fail",  //失败的大圆

			                orderSideOneLineColour: "bg-color-blue",
			                orderSideTwoLineColour: "bg-color-blue",
			                orderSideThreeLineColour: "bg-color-red",

			                orderStatusTwoTextColour: "font-color-red",
			                orderStatusThreeTextColour: "font-color-red"

		                });
		                break;
	                case 8:
						that.setData({
			                orderStatusTwoText:"处理订单",
			                orderStatusThreeText:"订单完成",

			                orderStatusOne: "bg-color-blue",  
			                orderStatusTwo: "bg-color-blue", 
			                orderStatusThree: "icon_doing",  //失败的大圆

			                orderSideOneLineColour: "bg-color-blue",
			                orderSideTwoLineColour: "bg-color-blue",
			                orderSideThreeLineColour: "bg-color-blue",

			                orderStatusTwoTextColour: "font-color-blue",
			                orderStatusThreeTextColour: "font-color-blue"

		                });
		                break;

                }
            }
        };
        app.ajax(opt);
	},


    onLoad(option) {
		let orderId = option.orderId;
		this.requestData(orderId)
    },
    onHide() {
        // app.removeStorageSync(app.globalData.globalData);
    },

	toUrl() {
		app.setStorageSync(app.globalData.passCache,this.data.data)
		app.navigateTo({url:'../passInformation/passInformation?type='+'enCode'})
	},

    progressTap(e) {
        let orderId = e.target.dataset.id;
        app.navigateTo({
            url: '../progress/progress?orderId='+orderId
        });
    }
});
